home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / CLINIC / MSGDLGS.PAS < prev    next >
Pascal/Delphi Source File  |  1997-04-25  |  1KB  |  51 lines

  1. unit MsgDlgs;
  2.  
  3. interface
  4.  
  5. uses
  6.   Forms, StdCtrls, Dialogs;
  7.  
  8. function MessageDlgDef(const Msg: string; AType: TMsgDlgType;
  9.   AButtons: TMsgDlgButtons; DefButton: TModalResult;
  10.   HelpCtx: Longint): TModalResult;
  11.  
  12. function MessageDlgDefPos(const Msg: string; AType: TMsgDlgType;
  13.   AButtons: TMsgDlgButtons; DefButton: TModalResult;
  14.   HelpCtx: Longint; X, Y: Integer): TModalResult;
  15.  
  16. implementation
  17.  
  18. function MessageDlgDef(const Msg: string; AType: TMsgDlgType;
  19.   AButtons: TMsgDlgButtons; DefButton: TModalResult;
  20.   HelpCtx: Longint): TModalResult;
  21. begin
  22.   Result := MessageDlgDefPos(Msg, AType, AButtons,
  23.     DefButton, HelpCtx, -1, -1);
  24. end;
  25.  
  26. function MessageDlgDefPos(const Msg: string; AType: TMsgDlgType;
  27.   AButtons: TMsgDlgButtons; DefButton: TModalResult;
  28.   HelpCtx: Longint; X, Y: Integer): TModalResult;
  29. var
  30.   I: Integer;
  31. begin
  32.   Result := 0;
  33.   with CreateMessageDialog(Msg, AType, AButtons) do
  34.     try
  35.       HelpContext := HelpCtx;
  36.       if X > -1 then Left := X;
  37.       if Y > -1 then Top := Y;
  38.       ScaleBy(Screen.PixelsPerInch, 96);
  39.       { Change the default button }
  40.       for I := 0 to Pred(ComponentCount) do
  41.         if Components[I] is TButton then
  42.           if TButton(Components[I]).ModalResult = DefButton then
  43.             ActiveControl := TButton(Components[I]);
  44.       Result := ShowModal;
  45.     finally
  46.       Free;
  47.     end;
  48. end;
  49.  
  50. end.
  51.